﻿using Asp.Versioning;
using FlyingEye.ComServices;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace FlyingEye.Controllers
{
    [Route("api/device-ops-service/v{version:apiVersion}/group-configurations")]
    [ApiVersion("1.0")]
    [ControllerName("ComeGroupNotificationConfiguration")]
    [Authorize]
    public class ComeGroupNotificationConfigurationController : DefaultController
    {
        private readonly ComeGroupNotificationConfigurationService _comeGroupNotificationConfigurationService;

        public ComeGroupNotificationConfigurationController(ComeGroupNotificationConfigurationService comeGroupNotificationConfigurationService)
        {
            _comeGroupNotificationConfigurationService = comeGroupNotificationConfigurationService;
        }

        [HttpGet("{id}", Name = "GetByComeGroupNotificationConfigurationId")]
        public async Task<ActionResult<ComeGroupNotificationConfigurationResponse>> GetAsync(Guid id)
        {
            return await GetInvokeAsync(async () =>
            {
                return await _comeGroupNotificationConfigurationService.GetAsync(id);
            });
        }

        [HttpPost]
        public async Task<ActionResult<ComeGroupNotificationConfigurationResponse>> InsertAsync([FromBody] CreateComeGroupNotificationConfigurationRequest group)
        {
            return await InsertInvokeAsync(async () =>
            {
                return await _comeGroupNotificationConfigurationService.InsertAsync(group);
            }, "GetByComeGroupNotificationConfigurationId", (result) => new { id = result.Id });
        }

        [HttpDelete("{id}")]
        public Task<NoContentResult> DeleteAsync(Guid id)
        {
            return DeleteInvokeAsync(async () =>
            {
                await _comeGroupNotificationConfigurationService.DeleteAsync(id);
            });
        }
    }
}
